package com.erp.serviceImpl.baseDataServiceImpl;

import com.erp.dao.DepotMapper;
import com.erp.pojo.Depot;
import com.erp.pojo.DepotExample;
import com.erp.service.baseDataService.DepotService;
import com.erp.utils.Msg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * Author:${JayC}
 * Date:2019/1/18
 * Time:17:39
 */
@Service
public class DepotServiceImpl implements DepotService {


    @Autowired
    private DepotMapper depotMapper;

    Msg msg = new Msg();
    @Override
    public Msg selectDepot(String name,int page, int limit) {

        DepotExample example= new DepotExample();
        DepotExample.Criteria criteria = example.createCriteria();

        if (name!=null&&!"".equals(name)){
            name="%"+name+"%";
            System.out.println(name);
            criteria.andNameLike(name);
        }

        PageHelper.startPage(page,limit);

        List<Depot> list = depotMapper.selectByExample(example);

        PageInfo<Depot> pagelist = new PageInfo<>(list);

        msg.setCode(0);
        msg.setCount(pagelist.getTotal());
        msg.setMsg("");
        msg.setData(pagelist.getList());

        System.out.println(msg);

        return msg;
    }

    @Override
    public void deleteDep(Long id) {
        depotMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insertDep(Depot depot) {
        depotMapper.insertSelective(depot);
    }


}
